package com.fusion.core.file.blockstorage;

import com.fusion.core.CoreSubsystem;

import java.io.IOException;

/**
 * @author SwethaShivakumar 
 * Project: fusion
 * Date: Mar 12, 2009
 * URL: http://fusionwiki.co.cc
 * Mail Me At: shiva@fusionproject.co.cc
 */
public class CacheStorage extends BlockStorage {
    public static final int TYPE_ID = 2;

    public CacheStorage(String storagePath, String completeFilePath, CoreSubsystem core) throws IOException {
        super(storagePath, completeFilePath, core);
        isSequential = false;
    }

    protected void signalFileComplete(BlockFile bf) {
        String path = bf.getFd().getFullPath();
        if(T.t)T.info("File in cache complete: "+path);

        if (bf.getFd().getRootHash().equals(core.getFileManager().getAutomaticUpgrade().getNewVersionHash())) {
            try {
                core.getFileManager().getAutomaticUpgrade().performUpgrade();
            } catch(Exception e) {
                core.reportError(new Exception("Automatic upgrade failed!", e), null);
            }
        }
    }

    public int getStorageTypeId() {
        return TYPE_ID;
    }
}
